package logic

import (
	"context"
	"goods_srv/goodsclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetGoodsEsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetGoodsEsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGoodsEsLogic {
	return &GetGoodsEsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetGoodsEsLogic) GetGoodsEs(req *types.GetGoodsEsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	goodsEs, err := l.svcCtx.GoodsSrv.GetGoodsEs(l.ctx, &goodsclient.GetGoodsEsRequest{
		Keyword: req.Keyword,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: 200,
		Msg:  "获取Es商品列表成功",
		Data: goodsEs,
	}, nil
}
